import { Component, Input } from '@angular/core';
import { DialogService } from 'ng-devui';
import { EncodeRulesService } from 'src/app/@core/services/encoderRule/encode-rules.service';
import { SelectPositionComponent } from 'src/app/@shared/components/select-position/select-position.component';
import { SelectUserComponent } from 'src/app/@shared/components/select-user/select-user.component';

@Component({
  selector: 'app-edit-work-shop',
  templateUrl: './edit-work-shop.component.html',
  styleUrls: ['./edit-work-shop.component.scss']
})
export class EditWorkShopComponent {
  @Input() data:any

  radioValue='否';
  workShop = {
    workshopNum: "",
    workshopName: "",
    workingHours: null,
    workshopSupervisorId: null,
    positionId: null
  }
  workshopSupervisorName = '';
  positionName = '';
  constructor(private dialogService:DialogService,private EncodeRulesService:EncodeRulesService){}
  ngOnInit(): void {
    this.workShop.positionId = this.data.rowItem.positionId
    this.workShop.workshopNum = this.data.rowItem.workshopNum
    this.workShop.workshopName = this.data.rowItem.workshopName
    this.workShop.workingHours = this.data.rowItem.workingHours
    this.workShop.workshopSupervisorId = this.data.rowItem.workshopSupervisorId
    this.workShop.positionId = this.data.rowItem.positionId
    this.workshopSupervisorName = this.data.rowItem.workshopSupervisorName
    this.positionName = this.data.rowItem.positionName

  }
  selectUser(dialogtype?: string){
    let data = {
      display: false,
      placeholder: '请选择人员'
    };
    const results = this.dialogService.open({
      id: 'department',
      width: '800px',
      title: '人员',
      data:data,
      content: SelectUserComponent,
      dialogtype: dialogtype,
      onClose: () => {
      },
      buttons: [
        {
          cssClass: 'stress',
          text: '确定',
          handler: ($event: Event) => {
            if(results.modalContentInstance.selectData){
              this.workShop.workshopSupervisorId = results.modalContentInstance.selectData.id
              this.workshopSupervisorName = results.modalContentInstance.selectData.name
              results.modalInstance.hide();
            }
            results.modalInstance.hide();
          },
        },
        {
          id: 'btn-cancel',
          cssClass: 'common',
          text: '取消',
          handler: ($event: Event) => {
            results.modalInstance.hide();
          },
        },
      ],
    });
  }//仓位信息
  selectPosition(dialogtype?: string){
    let data = {
      display: false,
      placeholder: '请选择仓位'
    };
    const results = this.dialogService.open({
      id: 'department',
      width: '900px',
      title: '仓位',
      data:data,
      content: SelectPositionComponent,
      dialogtype: dialogtype,
      onClose: () => {
      },
      buttons: [
        {
          cssClass: 'stress',
          text: '确定',
          handler: ($event: Event) => {
            if(results.modalContentInstance.selectData){
              this.workShop.positionId = results.modalContentInstance.selectData.positionId
              this.positionName = results.modalContentInstance.selectData.positionName
              results.modalInstance.hide();
            }
            results.modalInstance.hide();
          },
        },
        {
          id: 'btn-cancel',
          cssClass: 'common',
          text: '取消',
          handler: ($event: Event) => {
            results.modalInstance.hide();
          },
        },
      ],
    });
  }
}
